articles

Home / DeveloperSection / Articles / LINQ (Language Integrated Query)

LINQ (Language Integrated Query)

Amit Singh12221 27-Nov-2010

LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

In LINQ we used same format as SQL but some difference like positioning, style in Select, where etc. We use the System.Linq namespace.

Benefits of LINQ:

It provides rich Meta data.

Compile-time syntax checking

LINQ is static typing and provide intelliSence (previously available in imperative code).

It provides query in concise way. 

We create LINQ between LINQ to object, LINQ to XML, LINQ to SQL. 

LINQ to objects

The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or  IEnumerable <T> collection directly, without the use of an intermediate LINQ provider or API such as or LINQ to XML, LINQ to SQL. 

LINQ to SQL.

In Linq to sql , it changes into object model and sends to database for execution. After execution it find the result. So we easily maintain the relational database like query.

LINQ to XML

LINQ to XML provides an easy query interface for xml files. We do with linq to xml to read and write data from/to xml file, using the file for persistency maintaining a list of objects. Linq to xml can be used for storing application settings, storing persistent objects or any other data needs to be saved.

How use the LINQ in our program

Step1: we open the console application and write these codes

 

using System.Collections.Generic;
using System.Linq;
string[] Country = { "India", "SriLanka", "China", "Nepal", "Newzeland", "South Africa","America", "England" };
 
//In this section using LINQ Query
IEnumerable<string> query = from s in Country
                            where s.Length == 5
                            orderby s                 
                            select s.ToUpper();
 
foreach (string item in query)
Console.WriteLine(item);

 

Step2:Run it 

Output:

India

China

Nepal

 


Updated 14-Nov-2018

Leave Comment

Comments

Liked By